package com.dongdongshop.data;

/**
 * 统一响应结果封装
 */
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    //成功的方法
    public static Result ok(){
        return new Result(ResultEnum.OK.getCode(),ResultEnum.OK.getValue());
    }
    //失败的方法
    public static Result fail(){
        return new Result(ResultEnum.FAIL.getCode(),ResultEnum.FAIL.getValue());
    }

    //根据传入的不同值，响应不同的结果
    public static Result response(ResultEnum result){
        return new Result(result.getCode(),result.getValue());
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result() {
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }
}
